﻿package  Classes{
	
	public class Pieces {
	/*
	 * Soldier type 对于棋子而言 － 无棋子: 0x00 ; South的棋子0x0-, North 0x1- 
	 */
	public static const  FLAG_S:uint = 0x02;
	public static const  MINE_S:uint = 0x03;
	public static const  BOMB_S:uint = 0x04;
	public static const  SILING_S:uint = 0x05;
	public static const  JUNZHANG_S:uint = 0x06;
	public static const  SHIZHANG_S:uint = 0x07;
	public static const  LVZHANG_S:uint = 0x08;
	public static const  TUANZHANG_S:uint = 0x09;
	public static const  YINGZHANG_S:uint = 0x0A;
	public static const  LIANZHANG_S:uint = 0x0B;
	public static const  PAIZHANG_S:uint = 0x0C;
	public static const  GONGBING_S:uint = 0x0D;
	public static const  FLAG_N:uint = 0x12;
	public static const  MINE_N:uint = 0x13;
	public static const  BOMB_N:uint = 0x14;
	public static const  SILING_N:uint = 0x15;
	public static const  JUNZHANG_N:uint = 0x16;
	public static const  SHIZHANG_N:uint = 0x17;
	public static const  LVZHANG_N:uint = 0x18;
	public static const  TUANZHANG_N:uint = 0x19;
	public static const  YINGZHANG_N:uint = 0x1A;
	public static const  LIANZHANG_N:uint = 0x1B;
	public static const  PAIZHANG_N:uint = 0x1C;
	public static const  GONGBING_N:uint = 0x1D;
	public static const  INVALID:uint = 0x00;
	// tag for man or AI
	public static const  MAN_TAG:int = 0;
	public static const  AI_TAG:int = 1;
	public static const  UNKNOWN_TAG:int = -1;
	
	/**
	 * Pieces are the same player
	 * @param p0
	 * @param p1
	 * @return
	 */
	public static function  sameLocation ( p0:uint,  p1:uint):Boolean{
		if (p0 == Board.INVALID_BOARD_TAG || p1 == Board.INVALID_BOARD_TAG) {
			return false;
		}
		return getLocated(p0) == getLocated(p1);
	}
	
	/**
	 * get located from the piece
	 * 0 : man
	 * 1 : AI
	 */
	public static function getLocated( p:uint):int {
		if (p > 0x40) {
			return UNKNOWN_TAG;
		} else if (p > 0x30) {
			return UNKNOWN_TAG;
		} else if (p > 0x20) {
			return UNKNOWN_TAG;
		} else if (p > 0x10) {
			return AI_TAG;
		} else if (p > 0x00){
			return MAN_TAG;
		} else {
			return UNKNOWN_TAG;
		}
	}
	
	
	/**
	 * Convert the 0x3a, 0x2a, 0x1a to 0x0a
	 * 
	 * @param p
	 * @return
	 */
	public static function getPureType( p:uint):uint {
		if (p > 0x40) {
			return INVALID;
		} else if (p > 0x30) {
			return (p - 0x30);
		} else if (p > 0x20) {
			return  (p - 0x20);
		} else if (p > 0x10) {
			return (p - 0x10);
		} else {
			return p;
		}
	}
	
	/**
	 * Solider type <--> caption
	 */
	public static function pieceTitle( type:uint):String {
		var title:String = "n/a";
		switch (getPureType(type)) {
		case FLAG_S:
			title = "军旗";
			break;
		case MINE_S:
			title = "地雷";
			break;
		case BOMB_S:
			title = "炸弹";
			break;
		case SILING_S:
			title = "司令";
			break;
		case JUNZHANG_S:
			title = "军长";
			break;
		case SHIZHANG_S:
			title = "师长";
			break;
		case LVZHANG_S:
			title = "旅长";
			break;
		case TUANZHANG_S:
			title = "团长";
			break;
		case YINGZHANG_S:
			title = "营长";
			break;
		case LIANZHANG_S:
			title = "连长";
			break;
		case PAIZHANG_S:
			title = "排长";
			break;
		case GONGBING_S:
			title = "工兵";
			break;
		}
		return title;
	}


	}
	
}
